<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>基础表单</title>
    <link rel="stylesheet" href="__LIBS__/layui/css/layui.css" />
    <link rel="stylesheet" href="__MODULE__/admin.css?v=317" />
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        #formBasForm {
            max-width: 800px;
            margin: 30px 200px 50px;
        }

        .layui-form-item {
            display: flex ;
        }

        .layui-form-label {
            flex: 3;
        }

        .layui-input-block {
            flex: 14;
        }

        .layui-input-block {
            margin-left: 20px !important;
            min-height: 36px;
        }

        #formBasForm .layui-form-item {
            margin-bottom: 25px;
        }
    </style>
</head>

<body>
    <!-- 加载动画 -->
    <div class="page-loading">
        <div class="ball-loader">
            <span></span><span></span><span></span><span></span>
        </div>
    </div>
    <!-- 正文开始 -->
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <!-- 表单开始 -->
                <form class="layui-form" id="formBasForm" lay-filter="formBasForm">
                    <input type="hidden" name="id" value="{$item['id']?$item['id']:''}">
                    <input type="hidden" name="money" value="{$item['money']?$item['money']:'0.00'}">
                    <input type="hidden" name="credit" value="{$item['credit']?$item['credit']:'0'}">
                    <div class="layui-form-item">
                        <label class="layui-form-label">选择会员分组：</label>
                        <div class="layui-input-block">
                            <input id="classify" name="flid" value="{$item['flid']?$item['flid']:''}" placeholder="请选择会员分组" class="layui-hide"/>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">联系电话:</label>
                        <div class="layui-input-block">
                            <input name="phone" class="layui-input" value="{$item['phone']?$item['phone']:''}"/>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label ">余额:</label>
                        <div class="layui-input-block ">
                            <label >当前余额:{$item['money']?$item['money']:'0.00'}</label>
                            <input type="number" name="adjust_money" class="layui-input" value="" placeholder="调整数额与当前余额相加不能小于0" required lay-verify="num"/>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label ">积分:</label>
                        <div class="layui-input-block">
                            <label>当前积分:{$item['credit']?$item['credit']:'0'}</label>
                            <input type="number" name="adjust_credit" class="layui-input" value="" placeholder="调整数额与当前积分相加不能小于0" required lay-verify="num"/>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block" style="display: flex;
                    justify-content: space-around;
                ">
                            <button id="btnDemoEdtGetContent" class="layui-btn" lay-filter="formBasSubmit" lay-submit>&emsp;提交&emsp;</button>
                            <button type="reset" class="layui-btn layui-btn-primary">&emsp;重置&emsp;</button>
                        </div>
                    </div>
                </form>
                <!-- //表单结束 -->
            </div>
        </div>
    </div>

    <!-- js部分 -->
    <script type="text/javascript" src="__LIBS__/layui/layui.js"></script>
    <script type="text/javascript" src="__NJS__/common.js?v=317"></script>
    <script type="text/javascript" src="__LIBS__/tinymce/tinymce.min.js"></script>
    <script src="__LIBS__/jquery/jquery-3.2.1.min.js"></script>
    <script>
        layui.use(['layer', 'form', 'laydate','cascader','jquery','admin'], function () {
            var $ = layui.jquery;
            var layer = layui.layer;
            var form = layui.form;
            var laydate = layui.laydate;
            var admin = layui.admin;
            var cascader = layui.cascader;
            layui.use('upload', function () {
                var upload = layui.upload;

                //执行实例
                var uploadInst = upload.render({
                    elem: '#test1' //绑定元素
                    , url: '/upload/', //上传接口
                    accept: "images"
                    , done: function (res) {
                        //上传完毕回调
                    }
                    , error: function () {
                        //请求异常回调
                    }
                });
            });
            /* 渲染laydate */
            laydate.render({
                elem: '#formBasDateSel',
                trigger: 'click',
                range: true
            });
            cascader.render({
                elem: '#classify',
                reqData: function (values, callback, data) {
                    $.ajax({
                        url:"{:url('admin/vip/classify_list_json')}",
                        success:function(res){
                            //console.log(res)
                            if(res.code==0){
                                callback(res.data)
                            }
                        }
                    })
                },
                onChange: function (values, data) {
                    console.log(values);
                    console.log(data);
                }
            });

            /* 监听表单提交 */
            form.on('submit(formBasSubmit)', function (data) {
                //判断余额、积分
                var money = data.field.money;
                if (money*1 + data.field.adjust_money*1 < 0) {
                    layer.msg('余额不可以为负数');
                    return false;
                }
                var credit = data.field.credit;
                if (credit*1 + data.field.adjust_credit*1 < 0) {
                    layer.msg('积分不可以为负数');
                    return false;
                }
                $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
                $.ajax({
                    url:"{:url('vipedit')}",
                    type:'POST',
                    dataType:'json',
                    data:data.field,
                    success:function(res){
                        //console.log(res)
                        if (res.code == 0) {
                            layer.msg(res.msg,{icon:1,time:1500,shade:0.1})
                            setTimeout(function () {
                                admin.closeThisTabs();
                            }, 1000);
                        } else {
                            $(".layui-btn").removeClass('layui-disabled').removeAttr('disabled');
                            wk.error(res.msg);
                            return false;
                        }
                    }
                })
            });

        });
    </script>
</body>

</html>